home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-09-13 | 8.4 KB | 301 lines | [TEXT/MPS ] |
- /*---------------------------------------------------------------------------
- FILENAME
- ChooserSupport.c
-
- DESCRIPTION
- This file contains the C code for the PACK and LDEF routines used by the
- Chooser when the LaserWriter IISC driver is selected in the Chooser.
-
- 9/13/93 - dmh - Updated for the b2 seed.
-
- COPYRIGHT
- Copyright Apple Computer, Inc. 1992
- All rights reserved.
-
- INTERFACE ROUTINES:
- Device
- LDEF
-
- -------------------------------------------------------------------------------- */
-
- // Include the standard Mac header files
- #include "MacIncludes.h"
-
- // Include the new QuickDraw GX graphics header files
- #include <graphics routines.h>
-
- // Include the required Printing Manager header files
- #include <PrintingDrivers.h>
-
- /*********************************************************************************
- * CONSTANTS *
- *********************************************************************************/
-
- // Chooser initialize message selector
- #define initializeMsg 11
-
- // Icon Suite support
-
- #define ttNone 0x0000
- #define ttDisabled 0x0001
- #define ttOffline 0x0002
- #define ttOpen 0x0003
- #define ttSelected 0x4000
- #define ttSelectedDisabled (ttSelected + ttDisabled)
- #define ttSelectedOffline (ttSelected + ttOffline)
- #define ttSelectedOpen (ttSelected + ttOpen)
-
- #define ttLabel0 0x0000
- #define ttLabel1 0x0100
- #define ttLabel2 0x0200
- #define ttLabel3 0x0300
- #define ttLabel4 0x0400
- #define ttLabel5 0x0500
- #define ttLabel6 0x0600
- #define ttLabel7 0x0700
-
-
- /*********************************************************************************
- * INLINE DECLARATIONS *
- **********************************************************************************/
-
- pascal OSErr PlotIconSuite(const Rect * theRect, short align, short iconTransform, Handle cIcon)
- = {0x303C, 0x0603, 0xABC9};
-
- pascal void OldDrawText(const void *textBuf,short firstByte,short byteCount)
- = 0xA885;
-
-
- /***************************************************************************************
- * INTERFACE ROUTINES *
- ***************************************************************************************/
-
-
- /****************************************************************************************
-
- Device
-
- function:
- This routine is the interface routine for the Chooser PACK. This is the
- routine the Chooser calls to perform the Chooser functions for the
- LaserWriter IISC driver.
-
- parameters:
- message specifies which Chooser function to perform
- caller equals 1; specifies the caller is the Chooser
- objName name of the selected device
- zoneName zone name for AppleTalk devices
- theList the list of names
- p2 parameter used depending upon message value
-
- returns:
- OSErr
-
- ****************************************************************************************/
- pascal OSErr Device( short message,
- short caller,
- StringPtr objName,
- StringPtr zoneName,
- ListHandle theList,
- long p2)
- {
-
- OSErr anErr = noErr;
- extern Str31 gDriverName;
- extern gxJob gJob;
- StringPtr pDriverName = &gDriverName;
- gxJob *pJob = &gJob;
-
- if (message == initializeMsg) // T => Chooser PACK should initialize itself; start up QuickDraw GX
- {
- FCBPBRec pb;
-
- // determine the name of the driver selected
- pb.ioCompletion = nil;
- pb.ioNamePtr = pDriverName;
- pb.ioVRefNum = 0;
- pb.ioRefNum = CurResFile();
- pb.ioFCBIndx = 0;
- anErr = PBGetFCBInfo(&pb, false);
-
- // Now initialize QuickDraw GX
- *pJob = nil;
- if (anErr == noErr)
- {
- GXEnterGraphics();
- anErr = GXGetGraphicsError(nil);
- if (anErr == noErr)
- anErr = GXInitPrinting();
- }
- }
-
- // We let the system handle the device choosing for us
- if (anErr == noErr)
- anErr = GXHandleChooserMessage(pJob, pDriverName, message, caller, objName, zoneName, theList, p2);
-
- // Is it time to go away?
- if ( (message == terminateMsg) && (p2 == terminateMsg) )
- {
- GXExitPrinting();
- GXExitGraphics();
- }
-
- return(anErr);
- }
- /* Device */
-
-
-
- /****************************************************************************************
-
- LDEF
-
- function:
- This routine is the LDEF fro the Chooser PACK. It handles drawing the device
- list contents. The LDEF works in two modes:
- - if the first two characters of the cell are valid AppleTalk NBP names (ie, not ≈ ≈)
- then the LDEF is just a basic text LDEF
- - otherwise, it assumes the data is part of a PortListRec, which is
- a structure for icons with text underneath
-
- parameters:
- message what operation to perform on the list
- select is this cell to be selected or not?
- theRect rectangle of this cell, clipped to window
- theCell which cell this is
- dataOffset offset into data for this cell
- dataLen length of data for this cell
- theList the list to act upon
-
- returns:
- None
-
- ****************************************************************************************/
- pascal void LDEF(
- short message,
- Boolean select,
- Rect *theRect,
- Cell theCell,
- short dataOffset,
- short dataLen,
- ListHandle theList)
- {
- #pragma unused (theCell, dataLen)
-
- gxPortListRec theCellContents;
- Rect iconRect;
-
- switch (message)
- {
- case lDrawMsg:
- case lHiliteMsg:
-
- // save the data to avoid locking things down
- if (dataLen > sizeof(theCellContents) )
- dataLen = sizeof(theCellContents);
- BlockMove(((*(**theList).cells) + dataOffset), &theCellContents, dataLen );
-
- // draw the cell as an icon, but only if we see our magic marker at the front
- if ( (theCellContents.firstMarker == '≈') && (theCellContents.secondMarker == '≈') )
- {
- // center the icon rect on the list with a top margin of 10 pixels
- iconRect.top = theRect->top + 10;
- iconRect.left = theRect->left + ((theRect->right - theRect->left) >> 1) - 16;
- iconRect.bottom = iconRect.top + 32;
- iconRect.right = iconRect.left + 32;
-
-
- // draw the icon
- if (theCellContents.iconSuiteHandle != nil)
- PlotIconSuite(&iconRect,
- ttNone, (select) ? ttSelected: ttNone,
- theCellContents.iconSuiteHandle);
-
- // Get the general area under the icon in which to draw the label
- iconRect.left = theRect->left + 2;
- iconRect.right = iconRect.left + (**theList).cellSize.h - 2;
- iconRect.top = iconRect.bottom + 2;
- iconRect.bottom = theRect->bottom;
-
- // use a nice small font for the label
- TextFont(applFont);
- TextSize(9);
-
- {
- short labelWidth;
- short rectWidth;
- short labelHeight;
- FontInfo theInfo;
-
- // Get rid of any text that was there before
- EraseRect(&iconRect);
- iconRect.top += 2;
-
- // compute the height of the label
- GetFontInfo(&theInfo);
- labelHeight = theInfo.ascent + theInfo.leading;
-
- // compute where to draw the text
- iconRect.bottom = iconRect.top + labelHeight;
- rectWidth = iconRect.right-iconRect.left;
-
- // truncate the string to fit within the box
- TruncString(rectWidth, theCellContents.iconName, smTruncEnd);
-
- // compute the new width of the string
- labelWidth = StringWidth(theCellContents.iconName);
-
- // center the string, draw it
- iconRect.left += (rectWidth >> 1) - (labelWidth >> 1);
- MoveTo(iconRect.left, iconRect.bottom);
- DrawString(theCellContents.iconName);
-
- if (select)
- {
- // compute right and lower edge of box bounding the text we just drew
- iconRect.right = iconRect.left + labelWidth;
- iconRect.bottom += theInfo.descent;
-
- // outset it, and invert it to select it
- InsetRect(&iconRect, -1, -1);
- BitClr(pHiliteBit, HiliteMode);
- InvertRect(&iconRect);
- }
- }
-
- TextFont(applFont);
- TextSize(0);
- }
- else
- {
- // how boring! It's only text
- FontInfo theInfo;
- Rect ourRect;
-
- // add a margin to the rectangle
- ourRect = *theRect;
- ourRect.left += 3;
-
- // erase the rectangle
- GetFontInfo(&theInfo);
- EraseRect(theRect);
- MoveTo(ourRect.left, ourRect.bottom - theInfo.descent);
-
- // those darn other languages!
- if (GetSysJust() == teJustRight)
- Move(ourRect.right-ourRect.left-TextWidth((Ptr) &theCellContents, 0, dataLen) , 0);
-
- OldDrawText((Ptr) &theCellContents, 0, dataLen);
-
- // if selected, invert it
- if (select)
- InvertRect(theRect);
- }
-
- break;
-
- } // switch
-
- }
- /* LDEF */
-